<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>激光修复测试</title>
    <style>
        body {
            margin: 0;
            padding: 20px;
            background: #000;
            color: #fff;
            font-family: Arial, sans-serif;
        }
        canvas {
            border: 1px solid #333;
            background: #111;
        }
        .info {
            margin-top: 10px;
            padding: 10px;
            background: #222;
            border-radius: 5px;
        }
        .controls {
            margin-top: 10px;
            padding: 10px;
            background: #333;
            border-radius: 5px;
        }
        button {
            margin: 5px;
            padding: 8px 16px;
            background: #4a90e2;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background: #357abd;
        }
    </style>
</head>
<body>
    <h1>激光修复测试</h1>
    <canvas id="testCanvas" width="800" height="600"></canvas>
    <div class="info">
        <p>测试激光修复效果</p>
        <p>激光应该从玩家位置指向目标，而不是竖直线</p>
        <p>点击按钮测试不同角度的激光</p>
    </div>
    <div class="controls">
        <button onclick="testLaser(0)">向右 (0度)</button>
        <button onclick="testLaser(Math.PI/4)">右上 (45度)</button>
        <button onclick="testLaser(Math.PI/2)">向上 (90度)</button>
        <button onclick="testLaser(Math.PI)">向左 (180度)</button>
        <button onclick="testLaser(-Math.PI/2)">向下 (270度)</button>
    </div>

    <script src="js/utils.js"></script>
    <script src="js/weapon.js"></script>
    <script>
        // 模拟玩家类
        class MockPlayer {
            constructor(x, y) {
                this.x = x;
                this.y = y;
            }
        }
        
        // 模拟武器类
        class MockWeapon {
            constructor(player) {
                this.player = player;
            }
        }
        
        // 全局变量
        let testLaserBeam;
        let mockPlayer;
        let mockWeapon;
        
        // 初始化测试
        function initTest() {
            const canvas = document.getElementById('testCanvas');
            const ctx = canvas.getContext('2d');
            
            // 创建模拟对象
            mockPlayer = new MockPlayer(400, 300);
            mockWeapon = new MockWeapon(mockPlayer);
            
            // 渲染循环
            function render() {
                ctx.clearRect(0, 0, canvas.width, canvas.height);
                
                // 绘制网格
                ctx.strokeStyle = '#333';
                ctx.lineWidth = 1;
                for (let i = 0; i < canvas.width; i += 50) {
                    ctx.beginPath();
                    ctx.moveTo(i, 0);
                    ctx.lineTo(i, canvas.height);
                    ctx.stroke();
                }
                for (let i = 0; i < canvas.height; i += 50) {
                    ctx.beginPath();
                    ctx.moveTo(0, i);
                    ctx.lineTo(canvas.width, i);
                    ctx.stroke();
                }
                
                // 绘制玩家
                ctx.fillStyle = '#4a90e2';
                ctx.beginPath();
                ctx.arc(mockPlayer.x, mockPlayer.y, 10, 0, Math.PI * 2);
                ctx.fill();
                
                // 绘制玩家边框
                ctx.strokeStyle = '#ffffff';
                ctx.lineWidth = 2;
                ctx.stroke();
                
                // 绘制激光束
                if (testLaserBeam) {
                    testLaserBeam.render(ctx);
                }
                
                // 绘制说明文字
                ctx.fillStyle = '#fff';
                ctx.font = '16px Arial';
                ctx.fillText('点击按钮测试不同角度的激光', 10, 30);
                ctx.fillText('激光应该从玩家位置指向目标方向', 10, 50);
                
                requestAnimationFrame(render);
            }
            
            render();
        }
        
        // 测试特定角度的激光
        function testLaser(angle) {
            // 创建激光束
            testLaserBeam = new LaserBeam(
                mockPlayer.x,
                mockPlayer.y,
                angle,
                200, // 长度
                20,  // 伤害
                '#FF1493', // 颜色
                5000 // 生命周期
            );
            
            // 设置武器引用
            testLaserBeam.weapon = mockWeapon;
            
            console.log(`测试激光角度: ${angle} 弧度 (${angle * 180 / Math.PI} 度)`);
        }
        
        // 启动测试
        initTest();
    </script>
</body>
</html> 